package com.googlecode.afdbaccess.web.touch.webcontent.in_page.delete_row.delete_row_data;

import javax.annotation.security.RolesAllowed;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.DELETE;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;

import com.googlecode.afdbaccess.cache.preparedstatement.PreparedStatementArgumentsSetterHelper;
import com.googlecode.afdbaccess.config.injectconfig.ManagedRequestTransaction;
import com.googlecode.afdbaccess.web.common.interceptors.DatabaseAccessing;
import com.googlecode.afdbaccess.web.common.interceptors.RequestLogged;

@RolesAllowed("theRole")
@RequestLogged
@DatabaseAccessing
@Path("in-page/delete-row/delete-row-data")
public class DeleteRowDeleteRest {
    @Inject
    private ManagedRequestTransaction t;

    @DELETE
    @Path("{id}")
    @Produces("application/json")
    public String delete(@SuppressWarnings("unused") @Context HttpServletRequest request, @PathParam("id") long id) throws Exception {
        String sql = "";
        sql += "DELETE FROM webTable WHERE webTable_id=?";

        PreparedStatementArgumentsSetterHelper setter = new PreparedStatementArgumentsSetterHelper();
        setter.addArgument(id);

        t.executeUpdate(sql, setter);
        
        return "{\"success\": true, \"msg\": \"Row has been deleted.\"}";
    }
}
